package com.daervin.api.controller;

import com.daervin.common.code.CodeEnum;
import com.daervin.common.dto.Result;
import com.daervin.common.dto.request.SaveReq;
import com.daervin.svc.IAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by daervin on 2021/4/1
 */
@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private IAdminService adminService;

    @RequestMapping("/list")
    public Result<Boolean> test() {
        return new Result(true);
    }

    @RequestMapping("/save")
    public Result<String> save(@RequestBody SaveReq req) {
        if (req == null || StringUtils.isEmpty(req.getOriginalUrl()) || req.getLimitType() == null) {
            return new Result(CodeEnum.PAR_ERROR);
        }
        return adminService.saveNew(req);
    }
}
